package zzz.action;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import zzz.model.Company;
import zzz.service.CompanyService;
import zzz.service.ManagerService;

@Controller
@RequestMapping("/ecmanage")
public class ManageECAction {

	@Autowired
	public CompanyService managerService;
	
	@RequestMapping("/getAllCompanys")
	public String getAllCompanys(Map<String,List<Company>> m){
		List<Company> companyList=managerService.getAllCompanys();
		m.put("companyList", companyList);
		return "manager/ecManager";
	}
	
	@RequestMapping("/delCompany")
	public String delCompany(String ecId){
		System.out.println("ecId:"+ecId);
		managerService.delCompany(ecId);
		return "redirect:getAllCompanys";
	}
	
	@RequestMapping("/ecChange")
	public String ecChange(String ecId,Map<String,Company> m){
		Company company=managerService.getCompanyByEcId(ecId);
		m.put("company", company);
		return "manager/ecChange";
	}
	
	@RequestMapping("/updateCompany")
	public String updateCompany(Company company){
		managerService.updateCompany(company);
		return "redirect:getAllCompanys";
	}
	@RequestMapping("/ecManageAddEC")
	public String addECPage(){
		return "manager/ecManageAddEC";
	}
	@RequestMapping("/manageraddec")
	public String addEC(Map<String, String> m,Company company) {
		int i=managerService.addCompany(company);
		if(i!=0) {
			m.put("msg", "成功");
			m.put("herf", "getAllCompanys");
		}else {
			m.put("msg", "失败");
			m.put("herf", "getAllCompanys");
		}
		return "common/msgModal";
	}
}
